import React, { useState } from 'react'
import { ButtonEle, ButtonType } from '@/components/Buttton'
import Taro, { useDidShow } from '@tarojs/taro'
import { network } from '@/utils/network'
import {Button, Image, View} from '@tarojs/components'


import './index.scss'

export default () => {

    const [shop, setShop] = useState({});

      const getSite = () => {
          network.get('/xxm/shop/config').then(({ data, code }) => {
            if (code === 0) {
                console.log(data, 'data')
                setShop(data);
            }
        });
    }

    useDidShow(() => {
        getSite();
    })

    const login = async (e) => {
        const { code } = await Taro.login({})
        const { data: { token, user_id, partner_key } } = await network.post('/xxm/user/login', { code, userInfo: e.detail.userInfo });
        Taro.setStorageSync('authorization', token)
        Taro.setStorageSync('user_id', user_id)
        Taro.setStorageSync('partner_key', partner_key)
        Taro.navigateBack()
    }

    return (
        <View className='xxm-login-ls'>
            <View className='xxm-login-ls__header'>
                <View className='xxm-login-ls__logo'>
                    <Image src={shop?.logo} mode='widthFix' />
                </View>
                {/*<View className='xxm-login-ls__text'>印象爱乐</View>*/}
            </View>
            <View className='xxm-login-ls__footer'>
                <ButtonEle
                  block
                  type={ButtonType.PRI}
                  icon='attachment'
                  openType='getUserInfo'
                  onGetUserInfo={login}
                >微信授权绑定</ButtonEle>
                <ButtonEle
                  block
                  customStyle={{ marginTop: 20 }}
                  onClick={() => {
                        Taro.switchTab({
                            url: '/pages/me/me/index'
                        });
                    }}
                // type={ButtonType.PRI}
                // icon='attachment'
                // openType='getUserInfo'
                // onGetUserInfo={login}
                >取消</ButtonEle>
            </View>
        </View>
    )
}
